using LiJ.Common.Core;
using System.Collections.Generic;
using System.Xml;

namespace LiJ.Pay.WeiXin
{
	/// <summary>
	///   请求响应基类
	/// </summary>
	public class WxPayBaseResp : ResultMo
	{
		private SortedDictionary<string, object> _dics;

		/// <summary>   
		///    公众账号ID 必填 String(32) 调用接口提交的公众账号ID
		/// </summary>  
		public string appid
		{
			get;
			set;
		}

		/// <summary>   
		///    商户号 必填 String(32) 调用接口提交的商户号
		/// </summary>  
		public string mch_id
		{
			get;
			set;
		}

		/// <summary>   
		///   微信分配的子商户公众账号ID
		/// </summary>  
		public string sub_appid
		{
			get;
			set;
		}

		/// <summary>   
		///   微信支付分配的子商户号
		/// </summary>  
		public string sub_mch_id
		{
			get;
			set;
		}

		/// <summary>   
		///    随机字符串 必填 String(32) 微信返回的随机字符串
		/// </summary>  
		public string nonce_str
		{
			get;
			set;
		}

		/// <summary>   
		///    签名 必填 String(32) 微信返回的签名值，详见签名算法
		/// </summary>  
		public string sign
		{
			get;
			set;
		}

		/// <summary>   
		///    返回状态码 必填 String(16) SUCCESS/FAIL
		///     完全没意思，但是微信返回就收着吧
		/// </summary>  
		public string return_code
		{
			get;
			set;
		}

		/// <summary>   
		///    返回信息 可空 String(128) 返回信息，如非空，为错误原因签名失败
		/// </summary>  
		public string return_msg
		{
			get;
			set;
		}

		/// <summary>   
		///    业务结果 必填 String(16) SUCCESS/FAIL
		/// </summary>  
		public string result_code
		{
			get;
			set;
		}

		/// <summary>   
		///    错误代码 可空 String(32) 详细参见下文错误列表
		/// </summary>  
		public string err_code
		{
			get;
			set;
		}

		/// <summary>   
		///    错误代码描述 可空 String(128) 错误信息描述
		/// </summary>  
		public string err_code_des
		{
			get;
			set;
		}

		/// <summary>
		///   响应对象的xml实体
		/// </summary>
		protected internal XmlDocument RespXml
		{
			get;
			set;
		}

		/// <summary>
		/// 自定义索引，获取指定字段的值
		/// </summary>
		/// <param name="key"></param>
		public string this[string key]
		{
			get
			{
				object obj = default(object);
				this._dics.TryGetValue(key, out obj);
				return ((obj != null) ? obj.ToString() : null) ?? string.Empty;
			}
		}

		/// <summary>
		///  把消息对应的xml字典，给属性赋值
		/// </summary>
		/// <param name="contentDirs"></param>
		internal void FromResContent(SortedDictionary<string, object> contentDirs)
		{
			this._dics = contentDirs;
			this.return_code = this["return_code"];
			this.return_msg = this["return_msg"];
			this.nonce_str = this["nonce_str"];
			this.appid = this["appid"];
			this.mch_id = this["mch_id"];
			this.sub_appid = this["sub_appid"];
			this.sub_mch_id = this["sub_mch_id"];
			this.sign = this["sign"];
			this.result_code = this["result_code"];
			this.err_code = this["err_code"];
			this.err_code_des = this["err_code_des"];
			this.FormatPropertiesFromMsg();
		}

		/// <summary>
		/// 格式化自身属性部分
		/// </summary>
		protected virtual void FormatPropertiesFromMsg()
		{
		}
	}
}
